/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** ************************************************************************************************
 *  \file     Firewall_Mpc.h                                                                  *
 *  \brief    This file contains interface header for Semidrive Firewall MPC module.                    *
 *                                                                                                 *
 **************************************************************************************************/

#ifndef FIREWALL_MPC_H
#define FIREWALL_MPC_H

#ifdef __cplusplus
extern "C" {
#endif

/***************************************************************************************************
 *                                      Include header files                                       *
 **************************************************************************************************/
#include <Firewall.h>

/***************************************************************************************************
 *                                  Global Function Declarations                                   *
 **************************************************************************************************/
/**
 * \brief Configure the permission of memory port regions in MPC module.
 *
 * This function configure memory ports in MPC module.
 * The permissions of memory regions in MPC module should be locked after configuring.
 *
 * \param[in] ctrl the firewall instance.
 * \param[in] mpc_cfg  The configuration of memory.
 * \param[in] memport_num  The number of memory port.
 *
 * \return The result of the MPC initialization function.
 * \details - return FIREWALL_E_OK : initializa MPC success.
 *          - return FIREWALL_E_NULL_POINTER : The pointer is a NULL_PTR.
 *          - return FIREWALL_E_MPC_PORT_NUM : The number of memory port is unvalid.
 */
lld_status_t Firewall_MpcConfigure(const Firewall_ControllerType *ctrl,
                const Firewall_MpcMemPortConfigType *mpc_cfg, uint32_t memport_num);

/**
 * \brief Handle the interrupt status of the MPC module.
 *
 * This function get the illegal access error information of the MPC module.
 * The function exits as soon as it gets an illegal access message.
 * This function should be called by the firewall interrupt handler
 * Firewall_IrqHandler().
 *
 * \param[in] base the address of the MAC module.
 * \param[in] mpc_cfg  The configuration of memory.
 * \param[in] memport_num  The number of memory port.
 * \param[out] mpc_irqsta  The status of mpc interrupt.
 *
 * \return The result of the MPC handler.
 * \details - return FIREWALL_E_OK : Handle MPC interrupt success.
 *          - return FIREWALL_E_NULL_POINTER : The pointer is a NULL_PTR.
 *          - return FIREWALL_E_MPC_PORT_NUM : The number of memory port is unvalid.
 */
lld_status_t Firewall_MpcIrqHandler(uint32_t base,
                                       const Firewall_MpcMemPortConfigType *mpc_cfg,
                                       uint32_t memport_num,
                                       Firewall_MpcIrqStaType *mpc_irqsta);

/**
 * \brief Clear the interrupt status of the MPC module.
 *
 * This function will clear the interrupt registers in the MPC module.
 * This function should not be called after the firewall has been initialized.
 *
 * \param[in] base the address of the MAC module.
 * \param[in] mpc_cfg  The configuration of memory.
 * \param[in] memport_num  The number of memory port.
 */
void Firewall_MpcClearInterrupt(uint32_t base,
                                const Firewall_MpcMemPortConfigType *mpc_cfg,
                                uint32_t memport_num);

/**
 * \brief Control the interrupt of the MPC module.
 *
 * This function enable/disable the interrupt of illegal accessing for the MPC module.
 *
 * \param[in] base the address of the MAC module.
 * \param[in] mpc_cfg The pointer to memory ports configuration
 * \param[in] memport_num The number of memory ports
 * \param[in] enable Enable or disable the interrupts
 */
void Firewall_MpcInterruptEnable(uint32_t base, const Firewall_MpcMemPortConfigType *mpc_cfg,
                                        uint32_t memport_num, bool enable);

/**
 * brief Configure the permission of memory regions in MPC module.
 *
 * This function will be called by Firewall_MpcConfigure().
 *
 * param[in] base the address of the MAC module.
 * param[in] memory the address of the MPC port configuration.
 *
 * return The result of the configuration.
 * details - return FIREWALL_E_OK : initializa MPC regions success.
 *          - return FIREWALL_E_NULL_POINTER : The pointer is a NULL_PTR.
 *          - return FIREWALL_E_MPC_REGION_NUM : The number of regions in the
 *                                               port is unvalid.
 */
lld_status_t Firewall_MpcRegionConfigure(uint32_t base,
    const Firewall_MpcMemPortConfigType *memory);

#ifdef __cplusplus
}
#endif

#endif /* FIREWALL_MPC_H */

/* End of file */
